package com.mintyfresh.tns.client;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.util.*;
import com.mintyfresh.tns.util.*;


public class RoundResultWindow extends JComponent {
	/**
	 * These are the layers of the graphics object, in the order they are drawn onscreen 
	 * */
	private String roundTitle;
	private final String playerTitle = "Player";
	private final String scoreTitle = "Score";
	private ArrayList<String> playerNames;
	private ArrayList<String> scores;

	public RoundResultWindow(RoundResultInfo info) {
		playerNames = new ArrayList<String>();
		scores = new ArrayList<String>();
		HashMap<String, Double> roundScores = info.getRoundScores();
		roundTitle = "Round: " + info.getRoundNumber();
		for(String name : roundScores.keySet()) {
			playerNames.add(name);
			scores.add(new Double(Math.round(roundScores.get(name))).toString());
		}
	}

	/**
	 * Paint overrides JComponent's default paint
	 * Here we paint all the layers that make up the screen onto a 2D graphics object
	 * @author James
	 */
	public void paint(Graphics g) {
		Graphics2D g2d = (Graphics2D)g;
		g2d.drawLine(0, 20, 300, 20);
		g2d.drawLine(150, 20, 150, playerNames.size()*80);
		g2d.drawString(roundTitle, 120, 15);
		g2d.drawString(playerTitle, 20, 50);
		g2d.drawString(scoreTitle, 170, 50);
		for(int i = 0; i < playerNames.size(); i++) {
			g2d.drawString((String)playerNames.get(i), 20, (80+(i*20)));
			g2d.drawString((String)scores.get(i), 170, (80+(i*20)));
		}
	}
}
